package com.ruoyi.video.service.impl;

import com.ruoyi.video.domain.BusActiveCode;
import com.ruoyi.video.domain.BusMemberInfo;
import com.ruoyi.video.mapper.ActiveCodeMapper;
import com.ruoyi.video.mapper.MemberInfoMapper;
import com.ruoyi.video.service.IActiveCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ActiveCodeServiceImpl implements IActiveCodeService {

    @Autowired
    private MemberInfoMapper memberInfoMapper;

    @Autowired
    private ActiveCodeMapper activeCodeInfoMapper;

    @Override
    public BusActiveCode selectActiveCodeById(Long activeId) {
        return activeCodeInfoMapper.selectActiveCodeById(activeId);
    }

    @Override
    public BusActiveCode selectActiveCodeByCode(String activeCode) {
        return activeCodeInfoMapper.selectActiveCodeByCode(activeCode);
    }

    @Override
    public List<BusActiveCode> selectActiveCodeList() {
        return activeCodeInfoMapper.selectActiveCodeList();
    }

    @Override
    @Transactional
    public int batchInsertActiveCode(List<BusActiveCode> activeList) {
        for (BusActiveCode activeCode : activeList) {
            activeCodeInfoMapper.insertActiveCode(activeCode);
        }
        return 1;
    }

    @Override
    public int updateActiveCode(BusActiveCode activeCode) {
        return activeCodeInfoMapper.updateActiveCode(activeCode);
    }

    @Override
    @Transactional
    public int active(BusActiveCode activeCode, BusMemberInfo memberInfo) {
        this.updateActiveCode(activeCode);
        memberInfoMapper.updateMember(memberInfo);
        return 1;
    }

    @Override
    public int deleteActiveCodeById(Long activeId) {
        return activeCodeInfoMapper.deleteActiveCodeById(activeId);
    }

}
